import { tt } from "../../ttapi_interface/ttapi.js";
import * as tt2 from "../../ttapi_layer2/ttlayer2.js";
import { EUI_Style } from "./EUI_Style.js";

export enum EUI_Bitmap_EditTool {
    Drag,
    Draw,
}
export class EUI_Bitmap_Toolbox extends tt2.QUI_Panel {
    constructor() {
        super();
        this.backElement = EUI_Style.CreateDefaultBack();
        this.backElement.localRect.setAsFill();
        this.localRect.setVPosFill();
        this.localRect.setHPosByLeftBorder(26, 0);

        this.AddBtn(null, EUI_Bitmap_EditTool.Drag);
        this.AddBtn(null, EUI_Bitmap_EditTool.Draw);
    }
    tool: EUI_Bitmap_EditTool = EUI_Bitmap_EditTool.Drag;
    OnChange: (tool: EUI_Bitmap_EditTool) => void;
    AddBtn(icon: tt.Sprite, tool: EUI_Bitmap_EditTool) {

        let y = this.getChildCount() * 24
        let btn = EUI_Style.CreateToggle("D");
        this.addChild(btn);
        btn.localRect.setHPosFill();

        btn.localRect.setVPosByTopBorder(24, y);
        btn.OnChange = (v) => {
            if (v == false) {
                btn.value = true;

            }
            else {
                
                this.tool = tool;
                if (this.OnChange != null) {
                    this.OnChange(tool);
                }
                for (var i = 0; i < this.getChildCount(); i++) {
                    let t = this.getChild(i) as tt2.QUI_Toggle;
                    if (t != btn) {
                        t.value = false;
                    }
                }
            }

        }
    }
}